﻿using MediatR;
using Messhall.Domain.Permission.BusinessObjects;

namespace Messhall.Application.Permission.Commands;

/// <summary>
/// 删除用户
/// </summary>
public class RemoveUsersCommandHandler : CommandHandlerBase, INotificationHandler<RemoveUsersCommend>
{
    public async Task Handle(RemoveUsersCommend removeUsersCommend, CancellationToken cancellationToken)
    {
        var requst = removeUsersCommend.Request;
        
        List<Users> users = await base.usersRepository.FindAsync(requst.KeyIds.ToArray());

        foreach (var item in users)
        {
            item.SetIsDelete(true);
        }

        await appUnitOfWork.SaveChangesAsync();
    }
}